package user

import (
	"github.com/kataras/iris/v12"
	"huanteng/web/helpers"
	"huanteng/web/models"
	"huanteng/web/services"
)

type AuthController struct {
	Service services.UserService
}

func (a *AuthController) PostRegister(ctx iris.Context)*helpers.Response  {

	error:=a.Service.Register(ctx)
	if error!=nil{
		return helpers.FailedMsg(error.Error())
	}
	return helpers.SuccessMsg()
}

func (a *AuthController) PostLogin(ctx iris.Context)*helpers.Response {
	var user models.User
	ctx.ReadJSON(&user)
	m,err:=a.Service.Login(&user)
	if err!=nil{
		 return helpers.ErrorMsg(err.Error(),500)
	}
	return helpers.SuccessData(m)
}

func (a *AuthController) GetIndex(ctx iris.Context)*helpers.Response {
a.Service.Test()
 return helpers.AuthFailedMsg("fuck you baby")
}
/*func (a *AuthController) GetIndex() *helpers.Response {
	var user models.User
	_ = ctx.ReadJSON(&user)
	a.Service.Test()
	fmt.Println(user)
	fmt.Println("go")
	//middleware.JwtInit()
	return core.GenSuccessMsg("fuck")

}*/


